package com.dh.example.netty.enums;

import com.dh.example.netty.pojo.response.support.WsMsgExportDisposeResult;
import com.dh.example.netty.pojo.response.support.WsMsgImportDisposeResult;
import com.dh.example.netty.pojo.response.support.WsMsgLoginSuccess;
import com.dh.example.netty.pojo.response.support.WsMsgLoginUrl;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;


/**
 * ws resp类型枚举
 *
 * @author yolo
 * @date 2024/03/14 14:02:35
 */
@AllArgsConstructor
@Getter
public enum WsRespTypeEnum {

    /**
     * dataClass  后续存在在规划
     */
    LOGIN_URL_RESP("LOGIN_URL_RESP", "登录二维码返回", WsMsgLoginUrl.class),
    PING("PING", "心跳收到", null),
    LOGIN_SCAN_SUCCESS("LOGIN_SCAN_SUCCESS", "用户扫描成功等待授权", null),
    LOGIN_SUCCESS("LOGIN_SUCCESS", "用户登录成功返回用户信息", WsMsgLoginSuccess.class),
    INVALIDATE_TOKEN("INVALIDATE_TOKEN", "使前端的token失效，意味着前端需要重新登录", String.class),
    USER_ACCOUNT_CHANGE("USER_ACCOUNT_CHANGE", "用户账户状态变动", String.class),

    SYSTEM_MESSAGE_NOTIFICATION("SYSTEM_MESSAGE_NOTIFICATION", "系统消息通知", String.class),
    IMPORT_DISPOSE_RESULT("IMPORT_DISPOSE_RESULT", "导入数据处理结果返回", WsMsgImportDisposeResult.class),
    EXPORT_DISPOSE_RESULT("EXPORT_DISPOSE_RESULT", "导出处理结果返回", WsMsgExportDisposeResult.class),
    ;

    /**
     * 类型
     */
    private final String type;
    /**
     * desc
     */
    private final String desc;
    /**
     * 数据类
     */
    private final Class dataClass;

    private static final Map<String, WsRespTypeEnum> CACHE;

    static {
        CACHE = Arrays.stream(WsRespTypeEnum.values()).collect(Collectors.toMap(WsRespTypeEnum::getType, Function.identity()));
    }

    public static WsRespTypeEnum of(String type) {
        return CACHE.get(type);
    }
}
